import Vue from "vue"
import Router from "vue-router"

Vue.use(Router)

import Layout from "@/layout"

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/chart",
    children: [
      {
        path: "chart",
        name: "Chart",
        component: () => import("@/views/chart/index"),
        meta: { title: "项目概览", icon: "dashboard" }
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "pcSystemBuildMenu",
        name: "pcSystemBuildMenu",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/menu")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "appSystemBuildMenu",
        name: "appSystemBuildMenu",
        meta: {
          activeMenu: "/systemBuilding/appSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/appSystemBuilding/menu")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "settingPeople",
        name: "settingPeople",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/settingPeople")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "pcSystemBuildLayout",
        name: "pcSystemBuildLayout",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/layout")
      }
    ]
  },
  {
    path: "/systemBuilding",
    component: Layout,
    children: [
      {
        path: "settingCard",
        name: "settingCard",
        meta: {
          activeMenu: "/systemBuilding/pcSystemBuilding"
        },
        hidden: true,
        component: () => import("@/views/systemBuilding/pcSystemBuilding/settingCard")
      }
    ]
  }
]

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })
const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
